﻿app.controller("ngUserDetailController", function ($scope, $q, $http, LoginService, $location, $routeParams) {
    $scope.buybidamount = [{ Title: '15 Bids', Image: '../App/Images/15bids.jpg', Price: 9, BidAmount: 15 }, { Title: '25 Bids', Image: '../App/Images/25bids.jpg', Price: 15, BidAmount: 25 }, { Title: '50 Bids', Image: '../App/Images/50bids.jpg', Price: 30, BidAmount: 50 }, { Title: '100 Bids', Image: '../App/Images/100bids.jpg', Price: 60, BidAmount: 100 }, { Title: '250 Bids', Image: '../App/Images/250bids.jpg', Price: 150, BidAmount: 250 }, { Title: '500 Bids', Image: '../App/Images/500bids.jpg', Price: 300, BidAmount: 500 }, { Title: '1000 Bids', Image: '../App/Images/1000bids.jpg', Price: 600, BidAmount: 1000 }];
    $scope.walletfunds = [{ Amount: '5', Image: '../App/Images/5dollars.png' }, { Amount: '10', Image: '../App/Images/10dollars.png' }, { Amount: '20', Image: '../App/Images/20dollars.png' }, { Amount: '50', Image: '../App/Images/50dollars.jpg' }, { Amount: '100', Image: '../App/Images/100dollars.jpg' }];

    $scope.userDetail;
    $http.get("api/user/detail/").success(function (data) {
        $scope.userDetail = data;
        console.log(data);
    }).error(function (data) {
        console.log(JSON.stringify(data))
    });

    var getUserWins = function () {
        $http.get("api/user/winitems/").success(function (data) {
            $scope.wins = data;
            console.log(data);
        }).error(function (data) {
            console.log(JSON.stringify(data))
        });
    }
    getUserWins();

    $scope.showingUnPaid = true;
    $scope.checkStatus = function (win) {
        if ($scope.showingUnPaid) {
            return !win.WasPurchased;
        }
        return win.WasPurchased;
    }

    $scope.buttonValue = "Show Paid";
    $scope.flipper = function () {
        $scope.showingUnPaid = !$scope.showingUnPaid;
        if ($scope.showingUnPaid) {
            $scope.buttonValue = "Show Paid";
        } else {
            $scope.buttonValue = "Show UnPaid";
        }
    }
    $scope.newPassword = function (user) {
        console.log("new password");
        $http.post("/api/Account/ChangePassword/", user).success(function (data) {
            console.log(data);
            user.OldPassword = "";
            user.NewPassword = "";
            user.ConfirmPassword = "";
            $scope.showChangePassword = false;
        }).error(function (data) {
            console.log(data);

        });
    }

    $scope.dashboard = false;
    $scope.buybids = true;
    $scope.addfundstowallet = true;
    $scope.payItems = true;
    $scope.pageClass = 'page-dash';

    $scope.ngBuyBid = function () {
        $scope.buybids = false;
        $scope.dashboard = true;
        $scope.payItems = true;
        $scope.addfundstowallet = true;
        $scope.pageClass = 'page-bids';
    };
    $scope.buyBids = function (count, price) {
        var buyBidsVM = {
            UserName: $scope.userDetail.UserName,
            Bids: count,
            Cost: price
        };

        $http.put("/api/user/buybids", buyBidsVM).success(function (data) {
            $scope.userDetail = data;
        }).error(function (data) {
            console.log(data);
        });

    }
    $scope.ngAddWallet = function () {
        $scope.addfundstowallet = false;
        $scope.dashboard = true;
        $scope.payItems = true;
        $scope.buybids = true;
        $scope.pageClass = 'page-wallet';
    };
    $scope.addFunds = function (amount) {
        $http.put("/api/user/addsubtractmoney/" + amount).success(function (data) {
            $scope.userDetail.Wallet = data.Wallet;
        }).error(function (data) {
            console.log(JSON.stringify(data), "error on add money")
        });
    };

    $scope.ngUserDashboard = function () {
        $scope.dashboard = false;
        $scope.payItems = true;
        $scope.buybids = true;
        $scope.addfundstowallet = true;
        $scope.pageClass = 'page-dash';
    };
    $scope.ngUserItemsUnPaid = function () {
        $scope.payItems = false;
        $scope.dashboard = true;
        $scope.buybids = true;
        $scope.addfundstowallet = true;
        $scope.pageClass = 'page-items';
    };

    $scope.payUserBill = function () {
        $http.put("/api/user/buyitems/").success(function (data) {
            $scope.userDetail = data;
            getUserWins();
        }).error(function (data) {
            console.log(data);
        });
    };
});